package com.javafamily.controller;

import com.javafamily.bean.Pets;
import com.javafamily.service.PetsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/pets")
public class PetsController {
    @Autowired
    private PetsService petsService;

    @PostMapping("/save")
    public boolean saveHandler(@RequestBody Pets pets) {
        return petsService.savePets(pets);
    }

    @DeleteMapping("/delete/{id}")
    public boolean delHandler(@PathVariable("id") Integer id) {
        return petsService.removePetsById(id);
    }

    @PutMapping("/update")
    public boolean updateHandler(@RequestBody Pets pets) {
        return petsService.modifyPets(pets);
    }

    @GetMapping("/get/{id}")
    public Pets getHandler(@PathVariable("id") Integer id) {
        log.info("生产者的处理器方法被调用");
        return petsService.getPetsById(id);
    }

    @GetMapping("/list")
    public List<Pets> listHandler() {
        return petsService.listAllPets();
    }
}
